
// objTester.cpp : test program for the OBJ loading library
// Original version at http://www.kixor.net/dev/objloader/
// Modified by Anthony Dick
//
#include <stdio.h>
#include "objLoader.h"

void printVector(obj_vector *v)
{
	printf("%.2f,", v->e[0] );
	printf("%.2f,", v->e[1] );
	printf("%.2f  ",v->e[2] );
}

int main(int argc, char **argv)
{
	objLoader *objData = new objLoader();
    if (argc > 1) {
        objData->load(argv[1]);
    }
    else {
        printf("Usage: ./objtest model.obj\n");
        return 1;
    }

	printf("Number of vertices: %i\n", objData->vertexCount);
	printf("Number of vertex normals: %i\n", objData->normalCount);
	printf("Number of texture coordinates: %i\n", objData->textureCount);
	printf("\n");

	printf("Number of faces: %i\n", objData->faceCount);
	for(int i=0; i<objData->faceCount; i++)
	{
		obj_face *o = objData->faceList[i];
		printf(" face ");
		for(int j=0; j<3; j++)
		{
			printVector(objData->vertexList[ o->vertex_index[j] ]);
		}
		printf("\n");
	}

	printf("\n");

	printf("Number of materials: %i\n", objData->materialCount);
	for(int i=0; i<objData->materialCount; i++)
	{
		obj_material *mtl = objData->materialList[i];
		printf(" name: %s", mtl->name);
		printf(" amb: %.2f ", mtl->amb[0]);
		printf("%.2f ", mtl->amb[1]);
		printf("%.2f\n", mtl->amb[2]);

		printf(" diff: %.2f ", mtl->diff[0]);
		printf("%.2f ", mtl->diff[1]);
		printf("%.2f\n", mtl->diff[2]);

		printf(" spec: %.2f ", mtl->spec[0]);
		printf("%.2f ", mtl->spec[1]);
		printf("%.2f\n", mtl->spec[2]);		
		printf(" shiny: %.2f\n", mtl->shiny);

		printf(" texture: %s\n", mtl->texture_filename);
		printf("\n");
	}

	printf("\n");

	//vertex, normal, and texture test
    printf("Detailed face data:\n");
    for(int i=0; i<objData->faceCount; i++)
	{
		obj_face *o = objData->faceList[i];
		printf(" face ");
		for(int j=0; j<3; j++)
        {
            printf("%i/", o->vertex_index[j] );
            if (o->normal_index[j] >= 0) {                
                printf("%i/", o->normal_index[j] );
            }
            else {
                printf("No normal ");
            }
            if (o->texture_index[j] >= 0) {
                printf("%i ", o->texture_index[j]);
            }
            else {
                printf("No texture ");
            }
        }
        printf("\n");
    }

	return 0;

}



